public class Solution854 {
    public int peakIndexInMountainArray(int[] arr) {
        int l = 0;
        int r = arr.length - 1;
        //我要找一个精确值
        while (l <= r) {
            int mid = (r+l)/ 2;
            //相邻的数都比自己小
            if (arr[mid] > arr[mid - 1] && arr[mid] > arr[mid + 1]) {
                return mid;
            } else if (arr[mid] > arr[mid - 1] && arr[mid] < arr[mid + 1]) {//越来越大
                l = mid+1;
            } else {
                r = mid-1;
            }
        }
        return l;
    }

    public static void main(String[] args) {
        int[] arr = {1,2,7,6, 5, 4, 3, 2, 1};
        int i = new Solution854().peakIndexInMountainArray(arr);
        System.out.println(i);
    }
}
